package com.kailong.servlet.student;

import com.kailong.dao.admin.ManageSeatDao;
import com.kailong.pojo.Seat;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

@WebServlet("/student/studentSeatSelectAll")
public class StudentSeatSelectAll extends HttpServlet {
   protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
       response.setContentType("text/html;charset=utf-8");
     int cpage = 1;//
       int count = 10;//
       HttpSession session = request.getSession();
       String floor = request.getParameter("floor");
      String square = request.getParameter("square");
      String tstate = request.getParameter("tstate");
      String cp = request.getParameter("cp");
       String isLogin = (String) session.getAttribute("isLogin");

       if(cp!=null){
            cpage = Integer.parseInt(cp);
       }
      int arr[]  = ManageSeatDao.totalPage(count,floor,square);
        //获取所有用户记录
        ArrayList<Seat> list = ManageSeatDao.selectAll(cpage,count,floor,square,tstate);
        //放到请求对象域
        request.setAttribute("sseatlist",list);
        request.setAttribute("tsum",arr[0]);
        request.setAttribute("tpage",arr[1]);
        request.setAttribute("cpage",cpage);
        if(floor!=null && square != null){
            request.setAttribute("searchParams","&floor=" + floor + "&square=" + square);
        }
        if (isLogin.equals("1")) {
            request.getRequestDispatcher("studentSeatSelectAll.jsp").forward(request, response);
        }else{
            PrintWriter out = response.getWriter();
            out.print("<script>");
            out.print("alert('您还未登录！');window.location.href='../index.jsp' ");
            out.print("</script>");
        }
    }
}
